<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="java.util.*,com.telecom.tree.*,java.sql.*,com.telecom.cms.util.*,com.telecom.cms.dao.*,com.telecom.cms.dto.*"%>
<%@ taglib uri="/WEB-INF/tree.tld" prefix="tree"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Insert title here</title>
		<LINK href="images/main.css" type=text/css rel=stylesheet>
		<STYLE type=text/css>
BODY {
	SCROLLBAR-FACE-COLOR: #f2f2f2;
	SCROLLBAR-HIGHLIGHT-COLOR: #f2f2f2;
	SCROLLBAR-SHADOW-COLOR: #b7b7b7;
	SCROLLBAR-3DLIGHT-COLOR: #f2f2f2;
	SCROLLBAR-ARROW-COLOR: #999999;
	SCROLLBAR-TRACK-COLOR: #e9e9e9;
	SCROLLBAR-DARKSHADOW-COLOR: #f2f2f2;
	SCROLLBAR-BASE-COLOR: #f2f2f2;
}
</STYLE>
		<script type="text/javascript" src="js/dtree.js"></script>
		<script>
function subcheck(){
	var zdy=document.getElementById("yhzdycx");
	if(zdy){
		var mark="";
		var radiobutton=document.getElementsByName("radiobutton");
		for(i=0;i<4;i++){
			if(radiobutton[i].checked){
				mark=radiobutton[i].value;
			}
		}
		zdy.value=mark+" in ("+zdy.value+")";
	}
}


function changeParent(tree,nodeId){
	 aNodes = tree.aNodes;
	 truenodeid=nodeId.id.substring(tree.obj.length);
	//checked = document.getElementById(nodeId).checked;
	
	checked = nodeId.checked;
	if(checked){
		for(var i=0;i<aNodes.length;i++){
			if(aNodes[i].id == aNodes[truenodeid].pid){
				document.getElementById(tree.obj+i).checked = checked;
				changeParent(tree,document.getElementById(tree.obj+i));
				break;
			}
		}
	}else{
  	sign = 0;
		for(var i=0;i<aNodes.length;i++){
			if(aNodes[i].pid == aNodes[truenodeid].pid){
				if(document.getElementById(tree.obj+i).checked){
					sign = 1;
					break;
				}
			}
		}
		if(sign == 0){
			for(var i=0;i<aNodes.length;i++){
				if(aNodes[i].id == aNodes[truenodeid].pid){
					document.getElementById(tree.obj+i).checked = checked;
					changeParent(tree,document.getElementById(tree.obj+i));
					break;
				}
			}
		}
	}
}

function changeChild(tree,nodeId){
  //alert("tree is : "+tree.obj.length+" nodeid is :"+nodeId.id );
  //truenodeid=nodeId.id.substring(tree.obj.length);
  aNodes = tree.aNodes;
	//checked = document.getElementById(nodeId).checked;
	//alert(" nodeid is :"+nodeId );
	checked = nodeId.checked;
	//alert("tree is :  nodeid is :"+nodeId+" checked is:"+checked);
	for(var i=0;i<aNodes.length;i++){
	   // if(i>11) 
	   //   alert("pid is "+aNodes[i].pid+" & truenodeid is "+nodeId.id.substring(tree.obj.length)+" &id is "+aNodes[nodeId.id.substring(tree.obj.length)].id);
		if(aNodes[i].pid == aNodes[nodeId.id.substring(tree.obj.length)].id){
			document.getElementById(tree.obj+i).checked = checked;
			//alert(tree.obj+i);
			changeChild(tree, document.getElementById(tree.obj+i));
			//alert("return "+document.getElementById(tree.obj+i));
		}
		//else
		// alert (" why here?");
	}
}

//Add by wangxq@2007-6-15,选中单选按钮就自动选择上面的类别
function checkItem(str) 
{
  var e = window.event.srcElement; 
  //var all = eval("document.form_current_bill."+ str); 
  var all = document.getElementsByName(str); 
  for(var i=0;i<all.length;i++)
    if(all[i].value==e.name)
       all[i].checked = true;
    document.form_current_bill.submit();
}

function checkItemTextarea(str) 
{
  var e = window.event.srcElement; 
  var all = document.getElementsByName(str); 
  for(var i=0;i<all.length;i++)
    if(all[i].value==e.name)
    {
    	if(e.value!=""){
        	all[i].checked = true;
        }else if(e.value==""){
        	all[i].checked = false;
        }
    }
}

function checkItemtree() 
{
	checkItemMul('type');
}

function checkItemMul(str) 
{ 	
    var e = window.event.srcElement; 
    var all = eval("document.form_current_bill."+ str); 
    var i=0,j=0;
    for(i=0;i<all.length;i++)
      if(all[i].value==e.name)
        j=i;
    var a = document.getElementsByName(e.name); 
    if (all.length>1)
        all[j].checked = false;
    else
       	all.checked = false;
       	    
    for (i=0; i<a.length; i++) 
    { 
       if (a[i].checked)
       { 
         if (all.length>1)
            all[j].checked = true; 
         else
            all.checked = true;
         break;
       } 
    }
	if (all.length>1){
    	if(!all[j].checked)
       		document.getElementById("remove").value=e.name;
    }else{
    	if(!all.checked)
			document.getElementById("remove").value=e.name;
    }

    document.form_current_bill.submit(); 
    document.getElementById("remove").value="";
}

function upperCase(x)
{
	var y=document.getElementsByName("type");
	var e = window.event.srcElement;
	if (e.value=="")
	return;
	for(var j =0;j<y.length;j++){
	
	 if(y[j].value==x){
	 
	 y[j].checked = true;}
	}
	document.form_current_bill.submit(); 
}
 
function revalue(yy){

    var a = document.getElementsByName(yy);
    for(var i = 0 ; i < a.length ; i++){
    
        if(a[i].value == 99999){
        
           a[i].value = "" ;
        }
    }
}

function checkAll(str) 
{ 
  var a = document.getElementsByName(str); 
  var n = a.length;
  var o = window.event.srcElement; 
  var c = o.checked;
  for (var i=0; i<n; i++) 
     a[i].checked = c;
  if(!c){
    document.getElementById("remove").value=o.value;
  }
  document.form_current_bill.submit();
  document.getElementById("remove").value="";
} 
// end of Add by luory@2007-6-15,
function f_frameStyleResize(targObj){
  var targWin=targObj.parent.document.all[targObj.name];
  if(targWin!=null){
    var HeightValue=targObj.document.body.scrollHeight;
    targWin.style.pixelHeight=HeightValue;
  }
}
function f_iframeResize(){
  f_frameStyleResize(self);
}
window.onload=f_iframeResize;


</script>

	</head>
	<body>
		<%
					String latnid = request.getSession().getAttribute("latnid")
					.toString();
			Connection con = GetConnect.getCsConnection();
			int id = 0;
			if (null != request.getParameter("id"))
				id = Integer.parseInt(request.getParameter("id"));
			else
				id = Integer.parseInt(request.getAttribute("id").toString());
			SEG_ATOM_GROUP_RELDAO agdao = new SEG_ATOM_GROUP_RELDAO(con);
			List aglist = agdao.findById(id);
			List atomlist = new ArrayList();
			for (int i = 0; i < aglist.size(); i++) {
				SEG_ATOM_GROUP_RELDTO seg_ATOM_GROUP_RELDTO = (SEG_ATOM_GROUP_RELDTO) aglist
				.get(i);
				SEG_BIZ_ATOM_DEFDAO dao = new SEG_BIZ_ATOM_DEFDAO(con);
				SEG_BIZ_ATOM_DEFDTO dto = dao
				.findById(seg_ATOM_GROUP_RELDTO.getBIZ_ATOM_ID());
				if (null != dto.getBAS_TABLE_NAME()
				&& 100 != dto.getSHOW_TYPE_ID()) {
					atomlist.add(dto);
				}
			}
		%>

		<form action="rsrecord.do"
			<%=(latnid.equals("1000") && id == 3 ? ""
							: "target='rsFrame'")%>
			name="form_current_bill" method="post" onsubmit="subcheck()">


			<table border="0" align="left" cellpadding="0" cellspacing="0"
				width="100%" class="moduleList">
				<tr>
					<td valign="top">

						<table border="0" align="center" cellpadding="1" cellspacing="1"
							width="100%" class="moduleList">

							<%
											if (null != request.getAttribute("AddOrModiFlag")
											&& request.getAttribute("AddOrModiFlag").toString().equals(
											"Modi")) {//By Ruyi.Luo,如果是收藏里面的修改条件，则显示一个标头
							%>
							<tr>
								<td colspan="5">
									<table width="100%" cellspacing="0" cellpadding="0" border="0">
										<tr>
											<td width="3" height="31" align="right">
												<img height="31" src="images/table_01.gif" width="3" />
											</td>
											<td background="images/table_02.gif" width="99%" height="31">
												<table cellspacing="0" cellpadding="0" align="left"
													border="0">
													<tbody>
														<tr>
															<td width="51" background="images/title_1_bg.gif">
																<img height="31" src="images/title_1.gif" width="51" />
															</td>
															<td width="95" background="images/title_1_bg.gif">
																<span class="color_b_666">修改定制条件</span>
															</td>
														</tr>
													</tbody>
												</table>
											</td>
											<td width="3" align="left">
												<img height="31" src="images/table_03.gif" width="3" />
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<%
											}
											List outputList = (List) request.getSession().getAttribute(
											"AtomList");

											ShowatomDTO sAtom = null;
											for (int j = 0; j < atomlist.size(); j++) {

										if (0 == j % 4) {
							%>

							<tr bgcolor="#FFFFFF" align=center>
								<%
												}
												SEG_BIZ_ATOM_DEFDTO dto = (SEG_BIZ_ATOM_DEFDTO) atomlist
												.get(j);

												if (null != outputList)
													for (int myi = 0; myi < outputList.size(); myi++) {
												sAtom = (ShowatomDTO) outputList.get(myi);
												//out.print(sAtom.getAtomname()+"11"+dto.getBIZ_ATOM_NAME());
												if (null != sAtom
														&& sAtom.getAtomname().equals(
														dto.getBIZ_ATOM_NAME()))
													break;
												sAtom = null;
													}

												int actwidth = 190;
								%>
								<td align="center" valign="top" width="<%=actwidth%>">
									<TABLE width="100%" height="95" border=0 align="center"
										cellPadding=1 cellSpacing=0 bgColor=#D5D5D5 id=table16>
										<TR>
											<TD>
												<TABLE id=table17 cellSpacing=0 cellPadding=0 width="100%"
													bgColor=#ffffff border=0 align=center>

													<TBODY>
														<TR>
															<TD align=center>
																<TABLE id=table18 cellSpacing=0 cellPadding=3
																	width="100%" bgColor=#D5D5D5 border=0
																	background="images/atom_02.gif">
																	<TR>
																		<TD vAlign=top>
																			<SPAN class=en_big> <input type="checkbox"
																					id="type" name="type"
																					value="<%=dto.getBIZ_ATOM_NAME()%>"
																					<%=(null == sAtom ? "" : "checked")%>
																					onclick="checkAll('<%=dto.getBIZ_ATOM_NAME()%>')">
																				<%=dto.getBIZ_ATOM_NAME()%> </SPAN>
																		</TD>
																	</TR>
																</TABLE>
																<TABLE class=en_small id=table19 cellSpacing=0
																	cellPadding=0 width="100%" border=0>
																	<TR align="center">
																		<TD height="85" colspan="3" valign="top"
																			align="center">
																			<div style="height: 120px; overflow-y: auto;">
																				<table width="100%" border="0" cellspacing="0"
																					cellpadding="0">
																					<%
																						int showtypeid = dto.getSHOW_TYPE_ID();
																							String tablename = dto.getCDE_SRC_TABLE_NAME();

																							PreparedStatement ps = null;
																							ResultSet rs = null;
																					%>
																					<%
																						if (100001 == showtypeid) {
																								/*			String sql = "select * from " + tablename + " order by 1";
																											ps = con.prepareStatement(sql);
																											rs = ps.executeQuery();
																											List mea = new ArrayList();
																											while (rs != null && rs.next()) {

																												MEADTO meadto = new MEADTO();
																												meadto.setITEM_ID(rs.getObject(1).toString());
																												meadto.setSTART_VAULE(rs.getString(2));
																												meadto.setEND_VALUE(rs.getString(3));
																												mea.add(meadto);
																											}
																											if (rs != null) {

																												rs.close();
																											}
																											if (ps != null) {
																										ps.close();
																											}*/

																								HashMap atommap = Initmap.getatomMap();

																								ArrayList mea = (ArrayList) atommap.get(dto
																										.getBIZ_ATOM_NAME());
																					%>
																					<tr bgcolor="#FFFFFF">
																						<td>
																							从
																							<input id="<%=dto.getBIZ_ATOM_NAME()%>"
																								name="<%=dto.getBIZ_ATOM_NAME()%>" type="text"
																								size="1" maxlength="5"
																								onchange="upperCase('<%=dto.getBIZ_ATOM_NAME()%>')">
																							到
																							<input name="<%=dto.getBIZ_ATOM_NAME()%>"
																								type="text" size="1" maxlength="5" value="99999"
																								onfocus="revalue('<%=dto.getBIZ_ATOM_NAME()%>')">



																							<br>

																							<%
																								for (int k = 0; k < mea.size(); k++) {
																											MEADTO listdto = (MEADTO) mea.get(k);
																											String value = (listdto.getSTART_VAULE().trim() + "－" + listdto
																													.getEND_VALUE()).trim();
																							%>

																							<input type="checkbox"
																								name="<%=dto.getBIZ_ATOM_NAME()%>"
																								value="<%=value%>"
																								<%=(null != sAtom
										&& sAtom.getAtomvalue().indexOf(
												value + ",") > -1 ? "checked"
										: "")%>
																								onclick="checkItemMul('type')">
																							<%=value%>
																							<br>

																							<%
																								}

																									}

																									else if (2 == showtypeid) {

																										/*			String sql = "select * from " + tablename + " order by 1";
																												System.out.println(sql);
																												ps = con.prepareStatement(sql);
																												rs = ps.executeQuery();
																												List mea = new ArrayList();
																												while (rs != null && rs.next()) {

																											MEADTO meadto = new MEADTO();
																											meadto.setITEM_ID(rs.getObject(1).toString());
																											meadto.setSTART_VAULE(rs.getString(2));
																											meadto.setEND_VALUE("");
																											mea.add(meadto);
																												}
																												if (rs != null) {

																											rs.close();
																												}
																												if (ps != null) {
																											ps.close();
																												}  */
																										HashMap atommap = Initmap.getatomMap();

																										ArrayList mea = (ArrayList) atommap.get(dto
																												.getBIZ_ATOM_NAME());
																							%>
																						
																					<tr bgcolor="#FFFFFF">
																						<td>

																							<%
																								for (int k = 0; k < mea.size(); k++) {
																											MEADTO listdto = (MEADTO) mea.get(k);
																											String value = listdto.getEND_VALUE().trim();
																											//out.print(sAtom.getAtomvalue());
																							%>

																							<input type="checkbox"
																								name="<%=dto.getBIZ_ATOM_NAME()%>"
																								value="<%=listdto.getSTART_VAULE()%>"
																								<%=(null != sAtom
												&& sAtom
														.getAtomvalue()
														.indexOf(
																listdto
																		.getSTART_VAULE()) > -1 ? "checked"
												: "")%>
																								onclick="checkItemMul('type')">
																							<%=value%>
																							<br>

																							<%
																								}

																									}

																									else if (3 == showtypeid && 300001 != dto.getBIZ_ATOM_ID()) {
																							%>
																						
																					<tr bgcolor="#FFFFFF">
																						<td>

																							<%
																								List userTree = TreeUtil.retrieveNodeInfos(dto
																												.getCDE_SRC_TABLE_NAME());
																							%>
																							<script>
					  	                                                                                <%=TreeUtil.createTreeInfo(outputList, userTree, dto
									.getBIZ_ATOM_NAME())%>
					                                                                                         </script>

																							<%
																								}

																									else if (3 == showtypeid && 300001 == dto.getBIZ_ATOM_ID()) {
																							%>
																						
																					<tr bgcolor="#FFFFFF">
																						<td>




																							<%
																								List userFolderTree = null;
																										userFolderTree = TreeUtil.retrieveBranch_Name(latnid);
																							%>
																							<script>
					  	                                                                      <%=TreeUtil.createTreeInfo(outputList,
									userFolderTree, "地理位置细到支局")%>
					                                                                        </script>
																							<%
																								}

																									else if (200001 == showtypeid) {

																										/*			String sql = "select * from " + tablename + " order by 1";
																													ps = con.prepareStatement(sql);

																													rs = ps.executeQuery();
																													List mea = new ArrayList();
																													while (rs != null && rs.next()) {

																												MEADTO meadto = new MEADTO();
																												meadto.setITEM_ID("");
																												meadto.setSTART_VAULE(rs.getString(1));
																												meadto.setEND_VALUE(rs.getString(2));
																												mea.add(meadto);
																													}

																													if (rs != null) {

																												rs.close();
																													}
																													if (ps != null) {
																												ps.close();
																													}*/
																										HashMap atommap = Initmap.getatomMap();

																										ArrayList mea = (ArrayList) atommap.get(dto
																												.getBIZ_ATOM_NAME());
																							%>
																						
																					<tr bgcolor="#FFFFFF">
																						<td>
																							<%
																								for (int m = 0; m < mea.size(); m++) {

																											MEADTO listdto = (MEADTO) mea.get(m);
																											String value = listdto.getEND_VALUE().trim();
																							%>

																							<input type="radio"
																								name=<%=dto.getBIZ_ATOM_NAME()%>
																								value="<%=listdto.getSTART_VAULE()%>"
																								<%=(null != sAtom
												&& sAtom
														.getAtomvalue()
														.indexOf(
																listdto
																		.getSTART_VAULE()) > -1 ? "checked"
												: "")%>
																								onclick="checkItem('type')">
																							<%=value%>
																							<br>

																							<%
																								}

																									} else if (4 == showtypeid) {
																							%>
																							<textarea id="yhzdycx" rows="4" cols="60"
																								name="<%=dto.getBIZ_ATOM_NAME()%>"
																								title="在这里填入自定义sql语句"
																								onpropertychange="checkItemTextarea('type')"></textarea>
																							选择文本的类型:
																							<input type="radio" name="radiobutton"
																								value="Accs_Nbr" checked>
																							接入号码
																							<input type="radio" name="radiobutton"
																								value="Acct_Id">
																							账户标识
																							<input type="radio" name="radiobutton"
																								value="Cust_Id">
																							客户标识
																							<input type="radio" name="radiobutton"
																								value="prd_inst_id">
																							产品实例ID
																							<br>
																							<font color="red"><b>请在文本框填入可以得到4种id的语句或者直接用单引号包围的4种id然后选择对应的id</b>
																							</font>

																							<%
																								}
																							%>
																						</td>
																					</tr>
																				</table>
																			</div>
																		</TD>
																	</TR>
																</TABLE>
															</TD>
														</TR>
												</TABLE>
											</TD>
										</TR>
									</TABLE>
								</td>

								<%
									if ((0 == (j + 1) % 4) && j > 1) {
								%>

							</TR>
							<%
								}
							%>
							<%
								}

								for (int i = 0; i < 4 - atomlist.size() % 4; i++)
									out.print("<td></td>");
							%>
						</table>
					</td>
				</tr>
			</table>
			<input name="remove" id="remove" type="hidden" value="">
		</form>
	</body>
</html>
